$(document).ready(function () {
    $('#table').bootstrapTable({
        url: "index.php?g=Addition&m=Manufacturer&a=index",
        //classes:'table-no-bordered',        //表格边框
        queryParamsType: '',              //默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
        queryParams: queryParams,
        method: "post",
        pagination: true,
        pageNumber: 1,
        pageSize: 10,
        toolbar: "#toolbar",
        sortOrder: 'desc',
        toolbarAlign: 'right',      //toolbar位置
        pageList: [10, 20, 50, 100],
        sidePagination: "client",         //分页方式：client客户端分页，server服务端分页（*）
        striped: true,                    //是否显示行间隔色
        search:true,
        searchAlign:"left",
        showRefresh:true,               //是否显示刷新按钮
        cache: false,
        height:500,
        uniqueId: "uuid",               //每一行的唯一标识，一般为主键列
        idField: "uuid", //可以通过种方式设置主键
        paginationPreText: "上一页",
        paginationNextText: "下一页",
        columns: [
            {checkbox: true},
            {title: 'uuid', field: 'uuid',visible:false},
            { title: '序号', align: "center", formatter: function (value, row, index) { return index + 1; } },
            { title: '厂商编码',align: "center", field: 'supplier_id' },
            { title: '厂商名',align: "center", field: 'company_name' },
            { title: '厂商地址',align: "center", field: 'company_address' },
            {
                title: '操作' ,align:"center", field: 'uuid1', formatter: function (value, row, index) {
                console.log(row.uuid);
                var html = '<a href="index.php?g=Addition&m=Manufacturer&a=detail&uuid=' + row.uuid + '">编辑</a>';
                html += '&nbsp&nbsp|&nbsp&nbsp';
                html += '<a href="index.php?g=Addition&m=Manufacturer&a=delete&uuid='+row.uuid+'">删除</a>';
                return html;
            }
            }
        ],
    });
});

//查询条件

function queryParams(params) {
    return {
        pageSize: params.pageSize,
        pageIndex: params.pageNumber,
        Title: $.trim($("#txtTitle").val()),
        Author: $.trim($("#txtAuthor").val()),
        Publish: $.trim($("#txtPublish").val()),
    };
}

//查询事件
function SearchData() {
    $('#table').bootstrapTable('refresh', { pageNumber: 1 });
}


//批量删除
function BtchDeleteBook(){
    var opts = $('#table').bootstrapTable('getSelections');
    if (opts == "") {
        alert("请选择要删除的数据");
    }
    else {
        var idArray = [];
        for (var i = 0; i < opts.length; i++) {
            idArray.push(opts[i].BookId);
        }
        if (confirm("确定删除站位ID：" + idArray + "吗？")) {
            alert("执行删除操作");
        }
    }
}

function getTime(/** timestamp=0 **/) {
    var ts = arguments[0] || 0;
    var t, y, m, d, h, i, s;
    t = ts ? new Date(ts * 1000) : new Date();
    y = t.getFullYear();
    m = t.getMonth() + 1;
    d = t.getDate();
    h = t.getHours();
    i = t.getMinutes();
    s = t.getSeconds();
    // 可根据需要在这里定义时间格式
    return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d) + ' ' + (h < 10 ? '0' + h : h) + ':' + (i < 10 ? '0' + i : i) + ':' + (s < 10 ? '0' + s : s);
}

function getShortTime(/** timestamp=0 **/) {
    var ts = arguments[0] || 0;
    var t, y, m, d, h, i, s;
    t = ts ? new Date(ts * 1000) : new Date();
    y = t.getFullYear();
    m = t.getMonth() + 1;
    d = t.getDate();
    // 可根据需要在这里定义时间格式
    return y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d);
}
function add_data() {

    var data = {
        'staff_id': $("#staff_id").val(),
        'account': $("#account").val(),
        'password': $("#password").val(),
    };


    $.ajax({
        url: "index.php?g=personnel&m=Admin&a=AddAdmin1",
        type: 'post',
        data: data,
        datatype: 'json',
        success: function (res) {
            $("#myModal").modal('hide');
            res = eval(res);
            if (res['result'] == '1') {
                alert('添加成功！');
            } else {
                alert('添加失败，请稍后再试！');
            }
        },
        errer: function () {
            $("#myModal").modal('hide');
            alert('网络不佳，请稍后再试！')
        }

    })


}

